package zzj.campus_book_sharing_platform.Service.impl;

import org.springframework.stereotype.Service;
import zzj.campus_book_sharing_platform.Dao.answerDao;
import zzj.campus_book_sharing_platform.Entity.Answer;
import zzj.campus_book_sharing_platform.Service.AnswerService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class AnswerServiceImpl implements AnswerService {
    @Resource
    private answerDao answerDao;


    @Override
    public int insert(String answers, String postId, HttpSession session) {
        Answer answer = new Answer();
        answer.setAnswerId(String.valueOf(UUID.randomUUID()));
        answer.setContent(answers);
        answer.setCreatTime(new Date());
        answer.setPostId(postId);
        answer.setUserId((String) session.getAttribute("userId"));
        return answerDao.insert(answer);
    }

    @Override
    public int deleteById(String answerId, HttpSession session) {
        return answerDao.deleteById(answerId);
    }

    @Override
    public List<Answer> queryAllById(String postId, HttpSession session) {
        return answerDao.queryAllById(postId);
    }
}
